package net.arogarth.aws.android.manager.views;

import java.util.ArrayList;
import java.util.List;

import net.arogarth.aws.android.lib.def.Ec2InstanceTypes;
import net.arogarth.aws.android.manager.DatabaseAdapter;
import net.arogarth.aws.android.manager.R;
import net.arogarth.aws.android.manager.dbmodels.AvailabilityZone;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class LaunchInstanceFromAmi extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.launch_instance_from_ami);
		
		DatabaseAdapter dba = new DatabaseAdapter(getApplicationContext());
		dba.open();
		List<String> strKernelIds = dba.listKernelIds();
		
		@SuppressWarnings("unchecked")
		List<AvailabilityZone> availableZones = (List<AvailabilityZone>) new AvailabilityZone().list();
		dba.close();

		
		List<String> strAvailableZones = new ArrayList<String>();
		for(AvailabilityZone zone : availableZones) strAvailableZones.add(zone.getZone());
				
		ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(),
				android.R.layout.simple_spinner_dropdown_item, strKernelIds);
		((Spinner) findViewById(R.id.spKernelId)).setAdapter(ad);
		
		ad = new ArrayAdapter<String>(getApplicationContext(),
				android.R.layout.simple_spinner_dropdown_item, strAvailableZones);
		
		((Spinner) findViewById(R.id.spAvailableZone)).setAdapter(ad);
		
		
		ArrayAdapter<String> typeAdapter = new ArrayAdapter<String>(getApplicationContext(),
				android.R.layout.simple_spinner_dropdown_item, Ec2InstanceTypes.toList());
		((Spinner) findViewById(R.id.spInstanceType)).setAdapter(typeAdapter);
		
		
	}
}
